package com.tanhua.server.service.impl;

import cn.hutool.core.util.ObjectUtil;
import com.alibaba.dubbo.config.annotation.Reference;
import com.tanhua.dubbo.server.api.RecommendUserApi;
import com.tanhua.dubbo.server.pojo.RecommendUser;
import com.tanhua.dubbo.server.vo.PageInfo;
import com.tanhua.server.service.RecommendUserService;
import com.tanhua.server.vo.TodayBest;
import com.tanhua.server.vo.UserInformation;
import org.springframework.stereotype.Service;

import java.util.List;


/**
 * 负责与dubbo服务交互
 */
@Service
public class RecommendUserServiceImpl implements RecommendUserService {

    @Reference(version = "1.0.0")
    private RecommendUserApi recommendUserApi;

    @Override
    public TodayBest queryTodayBest(Long id) {
        RecommendUser recommendUser = this.recommendUserApi.queryWithMaxScore(id);
        if (null == recommendUser){
            return null;
        }

        TodayBest todayBest = new TodayBest();
        Long userId = recommendUser.getUserId();
        todayBest.setId(userId);
        //取整操作
        double score = Math.floor(recommendUser.getScore());
        todayBest.setFateValue(Double.valueOf(score).longValue());
        return todayBest;
    }

    @Override
    public PageInfo<RecommendUser> queryRecommendUserList(Long id, Integer page, Integer size) {
        return this.recommendUserApi.queryPageInfo(id, page, size);
    }

    /**
     * 查询探花卡片
     * @param id
     * @param count
     * @return
     */
    @Override
    public List<RecommendUser> queryCardList(Long id, Integer count) {
        return this.recommendUserApi.queryCardList(id, count);
    }

    /**
     * 查看缘分值， 类聚到RecommendUserService
     * @param userId
     * @param toUserId
     * @return
     */
    @Override
    public Double queryScore(Long userId, Long toUserId) {
        Double score = this.recommendUserApi.queryScore(userId, toUserId);
        if(ObjectUtil.isNotEmpty(score)){
            return score;
        }
        //默认值
        return 98d;
    }

}
